#include<bits/stdc++.h>
#define ll long long
#define L xd[x].l
#define R xd[x].r
#define mid ((l+r)>>1)
#define lc L,l,mid
#define rc R,mid+1,r
#define OK Ll<=l&&r<=Rr
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define repn(x) rep(x,1,n)
#define repm(x) rep(x,1,m)
#define pb push_back
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
#define Pi pair<int,int>
#define ui unsigned ll
inline ll read(){ll s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
inline void pf(int x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);}
using namespace std;
const int N=4e5+5,M=8e6+5,inf=(1LL<<31)-1,mod=1e9+7;
const ll llf=1e18;
inline void add(int &a,int b){((a+=b)>=mod) and (a-=mod);}
inline int Add(int a,int b){return add(a,b),a;}
inline int mul(int a,int b){return 1LL*a%mod*(b%mod)%mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline void red(int &a,int b){add(a,mod-b);}
inline int Red(int a,int b){return red(a,b),a;}
inline int qp(int a,ll b){if(!b)return 1;int c=qp(a,b>>1LL);Mul(c,c);if(b&1)Mul(c,a);return c;}
inline int INV(int x){return qp(x,mod-2);}
int m,n;
ll a[N],pr[N];
map<ll,bool>P;
inline void subtask1(){
	while(m--){
		ll x=read();
		n=0;
		if(P[x])P.erase(x);
		else P[x]=1;
		for(auto nw:P)a[++n]=nw.first;
		repn(i)pr[i]=pr[i-1]+a[i];
		if(!n){
			puts("0");
			continue;
		}
		ll ans=0,Ll=a[1],Rr=a[n]-1;
		rep(i,2,n){
			ll le=pr[i],re=pr[n]-pr[n-i]-1;
			if(le>Rr)ans+=Rr-Ll+1,Ll=le,Rr=re;
			else Rr=re;
		}
		cout <<ans+Rr-Ll+1<<'\n';
	}
}
ll lsh[N],b[N];
inline void subtask2(){
	repm(i)a[i]=lsh[i]=read();
	sort(lsh+1,lsh+m+1);
	repm(i)if(lsh[i]^lsh[i+1])b[++n]=lsh[i];
	
}
inline void Main(){
	m=read();
	if(m<=1000)return subtask1(),void();
	subtask2();
}
signed main(){
	freopen("kte.in","r",stdin);
	freopen("kte.out","w",stdout);
	int T=1;
	while(T--)Main();
	return 0;
}
